﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class page_Brand_Manager : PageBase
{
    private static DataTable dt = new DataTable();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            // 记录SiteID,UltraWebGrid控件分页时_Site.ID的值会丢失。
            if (_Site != null)
            {
                tbSiteID.Text = _Site.ID.ToString();
            }

            Utility.InitUltraWebGrid.InitDisplayLayOut(this.uwgMain);

            BindData();
        }
    }

    #region Web 窗体设计器生成的代码

    protected override void OnLoad(EventArgs e)
    {
        isRequestLogin = true;                                  //是否需要登录
        RequestLoginPage = this.Request.Url.AbsoluteUri;        //获取决对Url
        isAtFramePageLogin = true;                              //是框架页

        //RequestCompetences = Competences.BuildCompetencesList(Competences.PPGL_69);//页面权限

        base.OnLoad(e);
    }

    #endregion

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Response.Redirect("Brand_Edit.aspx?Action=Add&ID=" + ID + "");
    }

    protected void btnEdit_Click(object sender, EventArgs e)
    {
        Response.Redirect("Brand_Edit.aspx?Action=Edit&ID=" + this.hID.Value);
    }

    protected void btnStop_Click(object sender, EventArgs e)
    {
        int id = Shove._Convert.StrToInt((this.hID.Value), 0);  //选中行的ID

        DAL.Tables.tbl_Shop_Brand table = new DAL.Tables.tbl_Shop_Brand();
        table.Isuse.Value = 0;

        long i = table.Update("ID=" + id);

        if (i >= 0)
        {
            Shove._Web.JavaScript.Alert(this.Page, "成功停用该品牌信息！");
            BindData();
        }
      
        this.hID.Value = "";     
    }

    protected void btnResume_Click(object sender, EventArgs e)
    {
        int id = Shove._Convert.StrToInt((this.hID.Value), 0);  //选中行的ID

        DAL.Tables.tbl_Shop_Brand table = new DAL.Tables.tbl_Shop_Brand();
        table.Isuse.Value = 1;

        long i = table.Update("ID=" + id);

        if (i >= 0)
        {
            Shove._Web.JavaScript.Alert(this.Page, "成功启用该品牌信息！");
            BindData();
        }

        this.hID.Value = ""; 
    }

    protected void uwgMain_PageIndexChanged(object sender, Infragistics.WebUI.UltraWebGrid.PageEventArgs e)
    {
        BindData();
    }

    private void BindData()
    {
        if (dt != null && dt.Rows.Count > 0)
        {
            dt.Clear();
        }

        long SiteID = Shove._Convert.StrToLong(tbSiteID.Text, -1);

        string FieldList = "ID,BrandName_CN,BrandName_EN,Introduce,(case when Isuse = 1 then '正常' else '停用' end)as BrandStatus";

        dt = new DAL.Tables.tbl_Shop_Brand().Open(FieldList, "ShopID=-1 or ShopID=" + SiteID, "");

        this.uwgMain.DataSource = dt;
        this.uwgMain.DataBind();
    }

}
